import javax.swing.*;
import java.awt.peer.ChoicePeer;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Scanner;

public class Sufix extends JComboBox {


    public Sufix() {
       File prefixy = new File("/Users/tomaszsocha/Desktop/bw/wagaSuf.csv");;
        Scanner scanner = null;
        try {
            scanner = new Scanner(prefixy,"UTF-8");
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        try {
          //first use a Scanner to get each line
          while ( scanner.hasNextLine() ){
              String line = scanner.nextLine() ;
              String name = line.substring(0, line.indexOf(","));
              int waga = (int) Integer.parseInt(line.substring(line.indexOf(",")+1));
              this.addItem(name);
          }
        }
        finally {
          //ensure the underlying stream is always closed
          scanner.close();
        }

    }

     public Sufix(String itemName) {
       String fileLocation = "bw/"+itemName+"WagaSuf.csv";
        Scanner scanner = null;

        try {
            InputStream ms = getClass().getClassLoader().getResourceAsStream(fileLocation);
            scanner = new Scanner(ms,"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        try {
          //first use a Scanner to get each line
          while ( scanner.hasNextLine() ){
              String line = scanner.nextLine() ;
              String name = line.substring(0, line.indexOf(","));
              int waga = (int) Integer.parseInt(line.substring(line.indexOf(",")+1));
              this.addItem(name);
          }
        }
        finally {
          //ensure the underlying stream is always closed
          scanner.close();
        }

    }
}